<?php
//OJB: Check if for excel export process
ob_start();
?>
<?php
//debug($return_arr);
$cust  = $return_arr['cutomer_sales'][$customer_id];
?>
<div style="margin-bottom: 5px;">Customer: <strong id="customer_in_transaction"><?php echo ucwords(strtolower($cust['info']['name'])) ;?></strong></div>
<table class="tablep table-bordered">
    <thead>
    <tr>
        <th>Purchased Date</th>
        <th>Sales No</th>
        <th>Vehicle No</th>
        <th>Opening Balance <?php echo $tran_currency; ?></th>
        <th>Installment <?php echo $tran_currency; ?></th>
        <th>Total Repayment <?php echo $tran_currency; ?></th>
        <th>Undue <?php echo $tran_currency; ?></th>
        <th>Past Due <?php echo $tran_currency; ?></th>
        <th>Total Interest <?php echo $tran_currency; ?></th>
        <th>Principal Balance <?php echo $tran_currency; ?></th>
        <th>Total Balance <?php echo $tran_currency; ?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    if(isset($return_arr)){
        $data = $cust['sales'];
        foreach($data as $row){
            ?>
        <tr>
            <td><?php echo ucwords(strtolower($row['purchased_date']))?></td>
            <td><?php echo $row['invoice_number']?></td>
            <td><?php echo $row['vehicle_no']?></td>
            <td><?php echo number_format($row['opening_bal'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['mth_inst'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['repayment'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['undue'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['pastdue'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['interest'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['principal_bal'], 2, '.', ',')?></td>
            <td><?php echo number_format($row['total_bal'], 2, '.', ',')?></td>
        </tr>
            <?php
        }
    }
    ?>
    <tr>
        <td></td>
        <td></td>
        <td><strong>TOTAL</strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_opening_bal'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_mth_inst'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_repayment'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_undue'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_pastdue'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_interest'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_principal_bal'], 2, '.', ',')?></strong></td>
        <td><strong><?php echo number_format($return_arr['overall_totals']['overall_total_bal'], 2, '.', ',')?></strong></td>
    </tr>
    </tbody>
</table>
<?php
    $content = ob_end_flush();

    $filename = $file_name;
    $filename = str_replace(array(' ', '/', '\\'), '', $filename);
    $filename .= "_Export.xls";
    header('Content-type: application/ms-excel');
    header('Content-Disposition: attachment; filename='.$filename);
    echo $content;
    die();

?>